home *** CD-ROM | disk | FTP | other *** search
/ Ham Radio 2000 #1 / Ham Radio 2000.iso / ham2000 / tcp_ip / wnos / wn941101 / arpdump.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-10-07  |  1.7 KB  |  76 lines

  1. #include <conio.h>
  2. #include "global.h"
  3. #include "mbuf.h"
  4. #include "arp.h"
  5. #include "netuser.h"
  6. #include "trace.h"
  7.  
  8. void
  9. arp_dump(fp,bpp)
  10. FILE *fp;
  11. struct mbuf **bpp;
  12. {
  13.     struct arp arp;
  14.     struct arp_type *at;
  15.     char is_ip = 0, op = 0, tmp[30], buf[30];
  16.  
  17.     if(bpp == NULLBUFP || *bpp == NULLBUF)
  18.         return;
  19.  
  20.     if(ntoharp(&arp,bpp) == -1){
  21.         trprintf(fp,"ARP: bad packet\n");
  22.         return;
  23.     }
  24.  
  25.     at = (arp.hardware < NHWTYPES) ? &Arp_type[arp.hardware] : NULLATYPE;
  26.  
  27.     /* Print hardware type in Ascii if known, numerically if not */
  28.     textattr(LIGHTCYAN);
  29.     trprintf(fp,"ARP: len %d hwtype %s",
  30.         len_p(*bpp),
  31.         smsg(Arptypes,NHWTYPES,arp.hardware));
  32.  
  33.     /* Print hardware length only if unknown type, or if it doesn't match
  34.      * the length in the known types table
  35.      */
  36.     if(at == NULLATYPE || arp.hwalen != at->hwalen)
  37.         trprintf(fp," hwlen %u",arp.hwalen);
  38.  
  39.     /* Check for most common case -- upper level protocol is IP */
  40.     if(at != NULLATYPE && arp.protocol == at->iptype){
  41.         trprintf(fp," prot IP op ");
  42.         is_ip = 1;
  43.     } else {
  44.         trprintf(fp," prot 0x%x prlen %u op ",arp.protocol,arp.pralen);
  45.     }
  46.  
  47.     buf[0] = '\0';
  48.  
  49.     switch(arp.opcode){
  50.     case RARP_REQUEST:
  51.         strcpy(buf,"REVERSE ");
  52.     case ARP_REQUEST:
  53.         strcat(buf,"REQUEST");
  54.         break;
  55.     case RARP_REPLY:
  56.         strcpy(buf,"REVERSE ");
  57.     case ARP_REPLY:
  58.         strcat(buf,"REPLY");
  59.         op = 1;
  60.         break;
  61.     default:
  62.         sprintf(buf,"%u",arp.opcode);
  63.         break;
  64.     }
  65. /*    textattr(RED); */
  66.     trprintf(fp,"%s\n     HW: sender %s",buf,at->format(tmp,arp.shwaddr));
  67.     if(op)
  68.         trprintf(fp," target %s",at->format(tmp,arp.thwaddr));
  69.     trprintf(fp,"\n");
  70.     if(is_ip){
  71.         textattr(LIGHTGREEN);
  72.         trprintf(fp,"     IP: sender %s",inet_ntoa(arp.sprotaddr));
  73.         trprintf(fp," target %s\n",inet_ntoa(arp.tprotaddr));
  74.     }
  75. }
  76.